package com.hzqy.web.ac.itf;

import com.alibaba.fastjson.JSONObject;
import com.hzqy.service.ift.XpYunServiceBean;
import com.hzqy.web.vo.HotelUserNeedsVo;
import com.hzqy.web.vo.PmsOrgVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 芯烨云 接口api
 *
 */
@Controller
@RequestMapping("/itf/xpyunItf")
public class XpYunItfAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private XpYunServiceBean xpYunServiceBean;
	
	/**
	 * 添加打印机
	 */
	@RequestMapping("/addPrinters")
	@ResponseBody
	public Object addPrinters(String sn){
		long t1 = System.currentTimeMillis();
		LOG.debug("芯烨云API addPrinters 请求");
		Map<String, Object> resultMap = xpYunServiceBean.addPrinters(sn);
		LOG.debug("芯烨云API addPrinters 处理完成 : " + resultMap + " 耗时: " + (System.currentTimeMillis() - t1) + "ms.");
		return resultMap;
	}


    /**
     * 设置打印机语音类型
     */
    @RequestMapping("/setVoiceType")
    @ResponseBody
    public Object addPrinters(int voiceType,String sn){
        long t1 = System.currentTimeMillis();
        LOG.debug("芯烨云API setVoiceType 请求");
        Map<String, Object> resultMap = xpYunServiceBean.setVoiceType(voiceType, sn);
        LOG.debug("芯烨云API setVoiceType 处理完成 : " + resultMap + " 耗时: " + (System.currentTimeMillis() - t1) + "ms.");
        return resultMap;
    }


	/**
	 * 打印小票订单
	 */
	@RequestMapping("/print")
	@ResponseBody
	public Object print(@RequestBody String objectStr){
		long t1 = System.currentTimeMillis();
		LOG.debug("芯烨云API print 请求");
		System.out.println("接收的参数："+ objectStr );
		JSONObject jsonObject = JSONObject.parseObject(objectStr);
		HotelUserNeedsVo hotelUserNeedsVo = JSONObject.toJavaObject(jsonObject,HotelUserNeedsVo.class );
		Map<String, Object> resultMap = xpYunServiceBean.printHotelUserNeedsVo(hotelUserNeedsVo);
		LOG.debug("芯烨云API print 处理完成 : " + resultMap + " 耗时: " + (System.currentTimeMillis() - t1) + "ms.");
		return resultMap;
	}


    /**
     * 设置打印机语音类型
     */
    @RequestMapping("/playVoice")
    @ResponseBody
    public Object playVoice(String sn){
        long t1 = System.currentTimeMillis();
        LOG.debug("芯烨云API playVoice 请求");
        Map<String, Object> resultMap = xpYunServiceBean.playVoice(sn);
        LOG.debug("芯烨云API playVoice 处理完成 : " + resultMap + " 耗时: " + (System.currentTimeMillis() - t1) + "ms.");
        return resultMap;
    }

	
}
